#!/usr/bin/env python
# encoding: utf-8
'''
Created on Jun 9, 2011

@author: apple
'''
import sys
from optparse import OptionParser
from application import app

if __name__ == '__main__':
    app.run(host = '0.0.0.0',port=7777,debug=True)
    sys.exit(0)
    parser = OptionParser()
    parser.add_option('-r', '--runtype', dest='runtype' , default='raw',
                      help='Application run type,valid args \'raw\' \'geventwsgi\'.')
    parser.add_option('-d', '--daemon', dest='daemon',
                      help='Daemon run applition.', action='store_true')
    parser.add_option('-a', '--host', dest='host', default='127.0.0.1',
                      help='Application host.')
    parser.add_option('-p', '--port', dest='port', default=7777, type='int',
                      help='Application port.')
    parser.add_option('-l', '--log', dest='islogging', action='store_true',
                      help='Running in debug mode.')
    options, _a = parser.parse_args()
    
    options.islogging = options.islogging or False
    if options.runtype == 'geventwsgi':
        from gevent.wsgi import WSGIServer
        svr = WSGIServer((options.host, options.port), app)
        if options.daemon:
            import daemon
            with daemon.DaemonContext():
                log = '' if not options.islogging else 'default'
                svr.serve_forever(log=log)
        else:
            svr.serve_forever()
    elif options.runtype == 'raw':
        if options.daemon:
            import daemon
            with daemon.DaemonContext():
                app.run(options.host, options.port, debug=options.islogging)
        else:
            app.run(options.host, options.port, debug=options.islogging)
        
    
    
 

